<?php
('Access-Control-Allow-Origin：*');
include("../config/mysql.php");
$file_name = $_REQUEST['file_name'];
$company_id = $_REQUEST['company_id'];
$file_type = $_REQUEST["file_type"];
$limit = $_REQUEST['limit'];
$page = $_REQUEST['page'];

$sql = "SELECT f.id,f.file_name,f.file_path,f.type,c.companyName FROM files f INNER JOIN company c ON f.company_id = c.id WHERE company_id = {$company_id}";
if ($file_type) {
    $sql .= " AND f.type = {$file_type}";
}
if ($file_name) {
    $sql .= " AND f.file_name LIKE '%{$file_name}%'";
}
$sql .= ' order by id desc';
$Mysql = new Mysql();

$count = $Mysql->getResultNum($sql);
if ($count > 0) {
    $start = ($page - 1) * $limit;
    $sql .= " limit {$start},{$limit}";
    /*查询表格参数一表明   参数二 查询语句*/
    $arr = $Mysql->likeSelectLayui($sql);
}
/*返回出去*/
if (is_array($arr) == 1) {
    $res = [
        'code' => 0,
        'msg' => '查询成功',
        'count' => $count,
        'data' => $arr
    ];
} else {
    $res = [
        'msg' => '没有查到数据',
    ];
}
echo json_encode($res, JSON_UNESCAPED_UNICODE);
/*关闭连接*/
$Mysql->close();
